<template>
  <h1>循环指令</h1>
  <ul style="text-align: left">
    <li v-for="i in 3">{{ i }}</li>
  </ul>
  <ul style="text-align: left">
    <li v-for="i in arr">{{ i }}</li>
  </ul>
  <table border="1px">
    <tr>
      <th>序号</th>
      <th>商品名称</th>
      <th>商品价格</th>
      <th>商品库存</th>
      <th>操作</th>
    </tr>
    <tr v-for="(p,index) in arr">
      <td>{{ index + 1 }}</td>
      <td>{{ p.title }}</td>
      <td>{{ p.price }}</td>
      <td>{{ p.num }}</td>
      <td>
        <button @click="del(index)">删除</button>
      </td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";

let arr = ref([
  {title: "华为手机", price: 8888, num: 100},
  {title: "小米手机", price: 6666, num: 200},
  {title: "苹果手机", price: 9999, num: 300},
  {title: "三星手机", price: 5555, num: 400},
  {title: "魅族手机", price: 4444, num: 500},
  {title: "联想手机", price: 3333, num: 600},
]);
const del = (index) => {
  if (confirm('您确认要删除本商品吗?')) {
    arr.value.splice(index, 1);
  }
}
</script>

<style scoped>

</style>